from BinaryTree import *

class Solution:
	# @param root, a tree node
	# @return a list of integers
	def rightSideView(self, root):
		if root is None:
			return []
		ans = [root.val]
		que = [root, None]
		aa = root.val
		while len(que) > 1:
			r = que.pop(0)
			if r is None:
				que.append(None)
				ans.append(aa)
			else:
				if r.left is not None:
					que.append(r.left)
					aa = r.left.val
				if r.right is not None:
					que.append(r.right)
					aa = r.right.val
		return ans

if __name__ == '__main__':
	t = BinaryTree([1,2,3,'#',4,'#','#'])
	t.display()
	so = Solution()
	print so.rightSideView(t.tree())

